# coding: utf-8

from pyglet.event import EventDispatcher


import View
import CONTANTS

import random

class GameControl(EventDispatcher):
    def __init__(self):
        super(GameControl, self).__init__()
        # 初始化窗体
        self.GameViewer = View.GameView()
        self.reg_event()



    # 事件注册
    def reg_event(self):
        self.register_event_type('on_draw_game_view')
        self.register_event_type('on_draw_next_block')
        self.register_event_type('on_draw_current_block')








    # 绘制窗体/地图事件
    def on_draw_game_view(self):
        self.GameViewer.draw()

    # 绘制下一个方块事件
    def on_draw_next_block(self):
        self.next_block.draw()

    # 绘制当前方块事件
    def on_draw_current_block(self):
        self.current_block.draw()




    # 初始化下一个方块
    def draw_next_block(self):

        self.next_block = View.Block(img='data/block_%s.png' % random.choice(CONTANTS.colors),
                                     shape=random.choice(CONTANTS.shapes),
                                     pos=(10, 600)
                                     )

    # 初始化当前方块
    def draw_current_block(self):

        self.current_block = View.Block(img='data/block_%s.png' % random.choice(CONTANTS.colors),
                                        shape=random.choice(CONTANTS.shapes),
                                        pos=(CONTANTS.act_x, CONTANTS.act_y)
                                        )



